/*
Roles  http://alanning.github.io/meteor-roles/
Iron Router https://github.com/iron-meteor/iron-router
https://atmospherejs.com/mrt/flash-messages
https://github.com/stubailo/meteor-rest
*/

if (Meteor.isClient) {
  // counter starts at 0
  Session.setDefault('counter', 0);
  

  Template.hello.helpers({
    counter: function () {
      return Session.get('counter');
    }
  });

  Template.hello.events({
    'click button': function () {
      // increment the counter when button is clicked
      Session.set('counter', Session.get('counter') + 1);
    }
  });
}

if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup
    log.debug('meteor startup');
    console.log(Meteor.users.find({}).fetch());
  });
}

// http://www.bangnishouji.com/tools/chtounicode.html
function reconvert(str){ 
str = str.replace(/(\\u)(\w{1,4})/gi,function($0){ 
return (String.fromCharCode(parseInt((escape($0).replace(/(%5Cu)(\w{1,4})/g,"$2")),16))); 
}); 
str = str.replace(/(&#x)(\w{1,4});/gi,function($0){ 
return String.fromCharCode(parseInt(escape($0).replace(/(%26%23x)(\w{1,4})(%3B)/g,"$2"),16)); 
}); 
str = str.replace(/(&#)(\d{1,6});/gi,function($0){ 
return String.fromCharCode(parseInt(escape($0).replace(/(%26%23)(\d{1,6})(%3B)/g,"$2"))); 
}); 
return str; 
} 
